package com.xfcy.blog.controller.web;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.xfcy.blog.annotation.BusinessLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.CommentDTO;
import com.xfcy.blog.service.CommentService;
import com.xfcy.blog.valid.AddGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 晓风残月Lx
 * @date 2023/4/12 21:44
 */
@RestController
@RequestMapping("/web/comment")
@Api(tags = "前台评论管理")
public class WebCommentController {

    @Resource
    private CommentService commentService;

    /**
     * 查看评论  分页
     * @param pageNo
     * @param pageSize
     * @param articleId
     * @return
     */
    @BusinessLogger(value = "评论模块-用户评论",type = "添加",desc = "用户评论")
    @GetMapping("/comments")
    @ApiOperation(value = "评论模块-查看评论", httpMethod = "GET", response = R.class, notes = "评论模块-查看评论")
    public R getComments(Integer pageNo, Integer pageSize, Long articleId, Integer index) {
        return commentService.getComments(pageNo, pageSize, articleId, index);
    }

    /**
     * 查看评论回复 分页
     * @param pageNo
     * @param pageSize
     * @param commentId
     * @return
     */
    @BusinessLogger(value = "评论模块-查看回复评论", type = "查询", desc = "查看回复评价")
    @GetMapping("/repliesByComId")
    @ApiOperation(value = "评论模块-查看回复评论", httpMethod = "GET", response = R.class, notes = "评论模块-查看回复评论")
    public R repliesByComId(Integer pageNo, Integer pageSize, Integer commentId) {
        return commentService.repliesByComId(pageNo, pageSize, commentId);
    }

    @BusinessLogger(value = "评论模块-添加评论", type = "添加", desc = "添加评论")
    @PostMapping("/addComment")
    @ApiOperation(value = "评论模块-添加评论", httpMethod = "POST", response = R.class, notes = "评论模块-添加评论")
    @SaCheckLogin // 只有登录后才能进入此方法
    public R addComment(@Validated(AddGroup.class) @RequestBody CommentDTO commentDTO) {
        return commentService.addComment(commentDTO);
    }

    @BusinessLogger(value = "评论模块-评论点赞", type = "更新", desc = "评论点赞")
    @GetMapping("/commentLike")
    @ApiOperation(value = "评论模块-评论点赞", httpMethod = "GET", response = R.class, notes = "评论模块-评论点赞")
    @SaCheckLogin // 只有登录后才能进入此方法
    public R likeComment(Integer commentId, Long articleId) {
        return commentService.likeComment(commentId, articleId);
    }

    @BusinessLogger(value = "评论模块-删除评论", type = "删除", desc = "删除评论")
    @GetMapping("/deleteComment")
    @ApiOperation(value = "评论模块-删除评论", httpMethod = "GET", response = R.class, notes = "评论模块-删除评论")
    @SaCheckLogin // 只有登录后才能进入此方法
    public R deleteComment(Integer commentId) {
        return commentService.deleteComment(commentId);
    }


}
